const app = getApp()


Page({
  data: {
    config: app.globalData.config,
    wxUser: null,
    detail: null,
    showEmail:false,
    show: false,
    id:'1',
    name:'',
    phone:'',
    jobDetail:{/*title:"研究所电信组实习生",address:"上海",hours:"5天/8小时",total:"50-150天",img:"../../public/img/company2.png",company:"中智咨询",cate:"企业服务/咨询"*/},
    userInfo:{}
    /**{id:2,title:"前端开发工程师",address:"上海",hours:"5天/8小时",desc:["周末双休","五险一金","年终奖"],img:"../../public/img/company2.png",price:"10000-20000",date:"2-08",company:"中智咨询",cate:"企业服务/咨询",total:"50-150"} */
  },
  saveCollect(){
    var params = {
        id:null,
        bizId:this.data.id,
        type:1,
        createTime:new Date(),
        userId:this.data.userInfo.id
      }
   if(this.data.userInfo.id !=""){
    app.api.saveCollect(params)
    .then(res => {
        wx.showToast({
            title: '收藏成功',
            icon: 'success',
            duration: 2000
          })
     
    })
   }
  },
  postCollect(userId){
    
  },
  onShow(){
  
  },
  onLoad(option){
    this.setData({id:option.id})
    app.initPage().then(res => {
        this.setData({
            userInfo: app.globalData.wxUser
        })
        console.log(this.data.userInfo,'res')
        this.getWorkById()
    }) 
  },  
  getWorkById(){
    app.api.getWorkById(this.data.id)
    .then(res => {
      this.setData({
        jobDetail:res.data
      })
    })
  },
  //获取信息
  getWishById(){ 
    app.api.getWishById(this.data.id)
      .then(res => {
        console.log(res,'res')
        this.setData({
          detail: res.data
        })
      })
  },
  callPhone(){
    wx.makePhoneCall({
      phoneNumber: this.data.detail.phone,
      success: function() {

      } 
    })
  },
  onClose(){
    this.setData({
      showEmail: !this.data.showEmail
    })
    var pamrams = {
      wxUserId: this.data.userInfo.id,
      workId: this.data.id
    }
    app.api.workClick(pamrams)
  },
  openModel(){
    this.setData({
      show: !this.data.show
    })
  }, 
  inputNick(e){
    this.setData({
      name: e.detail
    })
  },
  inputPhone(e){
    this.setData({
      phone: e.detail
    })
  },
  handleSave(){
    var params = {
      wishId: this.data.detail.id,
      name: this.data.name,
      phone: this.data.phone
    }
    console.log(params.name,'11')
    if(params.name == ''){
      wx.showToast({
        title: '请填写姓名',
        icon: 'none'
      })
      return
    }
    if(params.phone == ''){
      wx.showToast({
        title: '请授权手机号',
        icon: 'none'
      }) 
      return
    }
    app.api.addApply(params)
    .then(res => {
      wx.showToast({
        title: '预约成功'
      })
      this.openModel()
      this.getWishById()
    })
  },
  // 授权 手机
  getPhoneNumber(e){
    console.log(e)
    var params = {
      jsCode: e.detail.code
    }
    app.api.getWxPhone(params).then(res => {
      console.log(res,'res')
      this.setData({
        phone: res.msg
      })
    })
  }
})
